package com.hr.outTime.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hr.common.annotation.Log;
import com.hr.common.core.controller.BaseController;
import com.hr.common.core.domain.AjaxResult;
import com.hr.common.enums.BusinessType;
import com.hr.outTime.domain.OutTime;
import com.hr.outTime.service.IOutTimeService;
import com.hr.common.utils.poi.ExcelUtil;
import com.hr.common.core.page.TableDataInfo;

/**
 * 设置保护期超时Controller
 * 
 * @author guan
 * @date 2024-08-01
 */
@RestController
@RequestMapping("/manage/time")
public class OutTimeController extends BaseController
{
    @Autowired
    private IOutTimeService outTimeService;

    /**
     * 查询设置保护期超时列表
     */
    @PreAuthorize("@ss.hasPermi('manage:time:list')")
    @GetMapping("/list")
    public TableDataInfo list(OutTime outTime)
    {
        startPage();
        List<OutTime> list = outTimeService.selectOutTimeList(outTime);
        return getDataTable(list);
    }

    /**
     * 获取设置保护期超时详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:time:query')")
    @GetMapping(value = "/{userLevel}")
    public AjaxResult getInfo(@PathVariable("userLevel") String userLevel)
    {
        int i = Integer.parseInt(userLevel);
        return success(outTimeService.selectOutTimeByUserLevel(i));
    }

    /**
     * 新增设置保护期超时
     */
    @PreAuthorize("@ss.hasPermi('manage:time:add')")
    @Log(title = "设置保护期超时", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OutTime outTime)
    {
        return toAjax(outTimeService.insertOutTime(outTime));
    }

    /**
     * 修改设置保护期超时
     */
    @PreAuthorize("@ss.hasPermi('manage:time:edit')")
    @Log(title = "设置保护期超时", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody List<OutTime> outTime)
    {
        return toAjax(outTimeService.updateOutTime(outTime));
    }

    /**
     * 删除设置保护期超时
     */
    @PreAuthorize("@ss.hasPermi('manage:time:remove')")
    @Log(title = "设置保护期超时", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userLevels}")
    public AjaxResult remove(@PathVariable Integer[] userLevels)
    {
        return toAjax(outTimeService.deleteOutTimeByUserLevels(userLevels));
    }

    /**
     * 解析Json
     */
//    public static void translate() {
//        String json = "[{\"id\":1,\"date\":\"2023-01-01\",\"outTime\":\"18:00\"},{\"id\":2,\"date\":\"2023-01-02\",\"outTime\":\"17:45\"}]";
//
//        ObjectMapper mapper = new ObjectMapper();
//        try {
//            List<OutTime> outTimes = mapper.readValue(json, mapper.getTypeFactory().constructCollectionType(List.class, OutTime.class));
//            System.out.println(outTimes);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//    }
}
